package io.itit.ecp.admin.provide.selected;

import io.itit.ecp.admin.server.entity.CarbonEmissionRangeEntity;
import io.itit.ecp.admin.server.service.ICarbonEmissionRangeService;
import io.itit.grass.common.provide.action.resp.SelectedResp;
import io.itit.grass.common.server.selected.ISelected;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;


@Component(value = CarbonEmissionRangeSelected.CODE)
@RequiredArgsConstructor
public class CarbonEmissionRangeSelected implements ISelected<SelectedResp> {

    public static final String CODE = "CarbonEmissionRangeSelected";

    private final ICarbonEmissionRangeService carbonEmissionRangeService;

    @Override
    public String code() {
        return CODE;
    }

    @Override
    public List<SelectedResp> get(String param) {
        return carbonEmissionRangeService.lambdaQuery()
                .orderByAsc(CarbonEmissionRangeEntity::getRangeName)
                .list()
                .stream()
                .map(t -> SelectedResp.builder().label(t.getRangeName()).value(t.getId()).build())
                .collect(Collectors.toList());
    }
}
